home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / jmtl028c.zip / SERTYPE.C < prev    next >
C/C++ Source or Header  |  1993-11-01  |  2KB  |  104 lines

  1.  
  2. /* received on 1/22/93 through E-Mail - typed from page 396 of old RKM  */
  3. /* modified by James McOrmond to provide simple type function for Jammail */
  4.  
  5. #include <stdio.h> 
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <exec/lists.h>
  9. #include <exec/ports.h>
  10. #include <exec/libraries.h>
  11. #include <exec/devices.h>
  12. #include <exec/io.h>
  13. #include <devices/serial.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <string.h>
  17.  
  18. struct IOExtSer *IORser;
  19. struct MsgPort *port;
  20. char buffer[200];
  21. extern struct MsgPort *CreatePort();
  22. extern struct IORequest *CreateExtIO();
  23.  
  24. int type(char *filename, char *device, int unit, unsigned long baud, unsigned char sf)
  25. {
  26.  
  27.     int WriteSer(struct IOExtSer *io, char *data);
  28.  
  29.     FILE *file;
  30.     char line[255];
  31.  
  32.     int ret = 1;
  33.     int error;
  34.  
  35.     port=CreatePort(device,unit);
  36.     if(port==NULL)
  37.     {
  38.     printf("Can't CreatePort!\n");
  39.     exit(100);
  40.     }
  41.   
  42.     IORser=(struct IOExtSer *)CreateExtIO(port,sizeof(struct IOExtSer));
  43.     if(IORser==NULL)
  44.     {
  45.     printf("Can't CreateExtIO\n");
  46.     goto cleanup1;
  47.     }
  48.  
  49.     IORser->io_ReadLen=0x08;
  50.     IORser->io_BrkTime=750000;
  51.     IORser->io_Baud=baud;
  52.     IORser->io_WriteLen=0x08;
  53.     IORser->io_StopBits=0x01;
  54.     IORser->io_RBufLen=2048;
  55.     IORser->io_SerFlags=sf;
  56.     IORser->io_TermArray.TermArray0=0x51040303;
  57.     IORser->io_TermArray.TermArray1=0x03030303;
  58.  
  59.     IORser->IOSer.io_Command=SDCMD_SETPARAMS;
  60.  
  61.     if((error=OpenDevice(device,unit,IORser,sf))!=0)
  62.     {
  63.         printf("Can't open device! : %ld\n",error);
  64.         goto cleanup1;
  65.     }
  66.  
  67.     if (file = fopen(filename, "r"))
  68.     {
  69.         ret = 0;
  70.         printf("Type: %s\n", filename);
  71.         while (fgets(line, 255, file))
  72.         {
  73.             strcat(line, "\r");
  74.             WriteSer(IORser,line);
  75.         }
  76.         fclose(file);
  77.     }
  78.     else
  79.         printf("Can't Find: %s\n", filename);
  80.  
  81.     cleanup2:
  82.     CloseDevice(IORser);
  83.  
  84.     cleanup1:
  85.     DeletePort(port);
  86.     return ret;
  87. }
  88.  
  89.  
  90. int WriteSer(struct IOExtSer *io, char *data)
  91. {
  92.     int error;
  93.  
  94.     io->IOSer.io_Data=(APTR)data;
  95.     io->IOSer.io_Length=-1;
  96.     io->IOSer.io_Command=CMD_WRITE;
  97.  
  98.     if((error=DoIO(io))!=0)
  99.     {
  100.         printf("write error:%ld\n",error);
  101.     }
  102.     return error;
  103. }
  104.